package com.shujia.mr.mc1;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 自己编写的map任务要继承hadoop中的Mapper类才算MR中的Map任务
 * MR底层map阶段中读取文件数据，默认是用LineRecoder(行读取器)进行读取的
 * 并且读取到map阶段之前，数据是以键值对的方式进入到Map阶段的
 */
public class MyMapper extends Mapper<LongWritable, Text,Text,LongWritable> {
        @Override
        protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context) throws IOException, InterruptedException {
                //<0L,"hello world java">  key value
                String line = value.toString();//取出一行数据
                //切分
                String[] word = line.split(" ");
                for (String s : word) {
                //context  hadoop上下文环境
                        context.write(new Text(s),new LongWritable(1L));

                }

        }
}
//由context将map的结果写道环形缓冲区进行分区编号，快速排序，落在磁盘上的小文件进行归并排序